
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/17/2013 20:40:04
-- Generated from EDMX file: D:\CandidateManager\trunk\WI.CandidateManager\WI.CandidateManager.Common\WI.CandidateManager.Common.Data\Entities\CMDBModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [D:\CANDIDATEMANAGER\TRUNK\WI.CANDIDATEMANAGER\WI.CANDIDATEMANAGER.PRESENTATION\CANDIDATEMANAGER\APP_DATA\CMDB.MDF];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_StudyGroupCouch_StudyGroup]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StudyGroupCouch] DROP CONSTRAINT [FK_StudyGroupCouch_StudyGroup];
GO
IF OBJECT_ID(N'[dbo].[FK_StudyGroupCouch_Couch]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StudyGroupCouch] DROP CONSTRAINT [FK_StudyGroupCouch_Couch];
GO
IF OBJECT_ID(N'[dbo].[FK_StudyGroupCandidate_StudyGroup]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StudyGroupCandidate] DROP CONSTRAINT [FK_StudyGroupCandidate_StudyGroup];
GO
IF OBJECT_ID(N'[dbo].[FK_StudyGroupCandidate_Candidate]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StudyGroupCandidate] DROP CONSTRAINT [FK_StudyGroupCandidate_Candidate];
GO
IF OBJECT_ID(N'[dbo].[FK_CandidateTaskBase_Candidate]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CandidateTaskBase] DROP CONSTRAINT [FK_CandidateTaskBase_Candidate];
GO
IF OBJECT_ID(N'[dbo].[FK_CandidateTaskBase_TaskBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CandidateTaskBase] DROP CONSTRAINT [FK_CandidateTaskBase_TaskBase];
GO
IF OBJECT_ID(N'[dbo].[FK_SubjectSchedule]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ScheduleSet] DROP CONSTRAINT [FK_SubjectSchedule];
GO
IF OBJECT_ID(N'[dbo].[FK_StudyGroupSchedule]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ScheduleSet] DROP CONSTRAINT [FK_StudyGroupSchedule];
GO
IF OBJECT_ID(N'[dbo].[FK_ScheduleOccurrence]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Occurrence] DROP CONSTRAINT [FK_ScheduleOccurrence];
GO
IF OBJECT_ID(N'[dbo].[FK_OccurrenceOccurenceResult]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OccurenceResultSet] DROP CONSTRAINT [FK_OccurrenceOccurenceResult];
GO
IF OBJECT_ID(N'[dbo].[FK_CandidateOccurenceResult]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OccurenceResultSet] DROP CONSTRAINT [FK_CandidateOccurenceResult];
GO
IF OBJECT_ID(N'[dbo].[FK_QuestionBaseAnswerBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_AnswerBase] DROP CONSTRAINT [FK_QuestionBaseAnswerBase];
GO
IF OBJECT_ID(N'[dbo].[FK_ResultBaseCandidate]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_ResultBase] DROP CONSTRAINT [FK_ResultBaseCandidate];
GO
IF OBJECT_ID(N'[dbo].[FK_ResultBaseTaskBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_ResultBase] DROP CONSTRAINT [FK_ResultBaseTaskBase];
GO
IF OBJECT_ID(N'[dbo].[FK_MarkBaseResultBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_MarkBase] DROP CONSTRAINT [FK_MarkBaseResultBase];
GO
IF OBJECT_ID(N'[dbo].[FK_MarkBaseOccurenceResult]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_MarkBase] DROP CONSTRAINT [FK_MarkBaseOccurenceResult];
GO
IF OBJECT_ID(N'[dbo].[FK_TaskBaseUserBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_TaskBase] DROP CONSTRAINT [FK_TaskBaseUserBase];
GO
IF OBJECT_ID(N'[dbo].[FK_EntityBaseAttachment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AttachmentSet] DROP CONSTRAINT [FK_EntityBaseAttachment];
GO
IF OBJECT_ID(N'[dbo].[FK_CoachSubject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Subject] DROP CONSTRAINT [FK_CoachSubject];
GO
IF OBJECT_ID(N'[dbo].[FK_TestQuestionBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_QuestionBase] DROP CONSTRAINT [FK_TestQuestionBase];
GO
IF OBJECT_ID(N'[dbo].[FK_GroupBase_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_GroupBase] DROP CONSTRAINT [FK_GroupBase_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_StudyGroup_inherits_GroupBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_StudyGroup] DROP CONSTRAINT [FK_StudyGroup_inherits_GroupBase];
GO
IF OBJECT_ID(N'[dbo].[FK_UserBase_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_UserBase] DROP CONSTRAINT [FK_UserBase_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Coach_inherits_UserBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Coach] DROP CONSTRAINT [FK_Coach_inherits_UserBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Candidate_inherits_UserBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Candidate] DROP CONSTRAINT [FK_Candidate_inherits_UserBase];
GO
IF OBJECT_ID(N'[dbo].[FK_TaskBase_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_TaskBase] DROP CONSTRAINT [FK_TaskBase_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Subject_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Subject] DROP CONSTRAINT [FK_Subject_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Occurrence_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Occurrence] DROP CONSTRAINT [FK_Occurrence_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_QuestionBase_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_QuestionBase] DROP CONSTRAINT [FK_QuestionBase_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_AnswerBase_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_AnswerBase] DROP CONSTRAINT [FK_AnswerBase_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_ResultBase_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_ResultBase] DROP CONSTRAINT [FK_ResultBase_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_MarkBase_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_MarkBase] DROP CONSTRAINT [FK_MarkBase_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Test_inherits_TaskBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Test] DROP CONSTRAINT [FK_Test_inherits_TaskBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Admin_inherits_UserBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Admin] DROP CONSTRAINT [FK_Admin_inherits_UserBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Coursework_inherits_TaskBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Coursework] DROP CONSTRAINT [FK_Coursework_inherits_TaskBase];
GO
IF OBJECT_ID(N'[dbo].[FK_Homework_inherits_TaskBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Homework] DROP CONSTRAINT [FK_Homework_inherits_TaskBase];
GO
IF OBJECT_ID(N'[dbo].[FK_SingleQuestion_inherits_QuestionBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_SingleQuestion] DROP CONSTRAINT [FK_SingleQuestion_inherits_QuestionBase];
GO
IF OBJECT_ID(N'[dbo].[FK_SingleAnswer_inherits_AnswerBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_SingleAnswer] DROP CONSTRAINT [FK_SingleAnswer_inherits_AnswerBase];
GO
IF OBJECT_ID(N'[dbo].[FK_TaskResult_inherits_ResultBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_TaskResult] DROP CONSTRAINT [FK_TaskResult_inherits_ResultBase];
GO
IF OBJECT_ID(N'[dbo].[FK_TaskMark_inherits_MarkBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_TaskMark] DROP CONSTRAINT [FK_TaskMark_inherits_MarkBase];
GO
IF OBJECT_ID(N'[dbo].[FK_FreeTextAnswer_inherits_AnswerBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_FreeTextAnswer] DROP CONSTRAINT [FK_FreeTextAnswer_inherits_AnswerBase];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[EntityBaseSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet];
GO
IF OBJECT_ID(N'[dbo].[ScheduleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ScheduleSet];
GO
IF OBJECT_ID(N'[dbo].[OccurenceResultSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OccurenceResultSet];
GO
IF OBJECT_ID(N'[dbo].[AttachmentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AttachmentSet];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_GroupBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_GroupBase];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_StudyGroup]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_StudyGroup];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_UserBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_UserBase];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Coach]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Coach];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Candidate]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Candidate];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_TaskBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_TaskBase];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Subject]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Subject];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Occurrence]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Occurrence];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_QuestionBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_QuestionBase];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_AnswerBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_AnswerBase];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_ResultBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_ResultBase];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_MarkBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_MarkBase];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Test]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Test];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Admin]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Admin];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Coursework]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Coursework];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Homework]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Homework];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_SingleQuestion]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_SingleQuestion];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_SingleAnswer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_SingleAnswer];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_TaskResult]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_TaskResult];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_TaskMark]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_TaskMark];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_FreeTextAnswer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_FreeTextAnswer];
GO
IF OBJECT_ID(N'[dbo].[StudyGroupCouch]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StudyGroupCouch];
GO
IF OBJECT_ID(N'[dbo].[StudyGroupCandidate]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StudyGroupCandidate];
GO
IF OBJECT_ID(N'[dbo].[CandidateTaskBase]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CandidateTaskBase];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'EntityBaseSet'
CREATE TABLE [dbo].[EntityBaseSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [State] tinyint  NOT NULL
);
GO

-- Creating table 'ScheduleSet'
CREATE TABLE [dbo].[ScheduleSet] (
    [SubjectId] bigint  NOT NULL,
    [StudyGroupId] bigint  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL,
    [State] tinyint  NOT NULL
);
GO

-- Creating table 'OccurenceResultSet'
CREATE TABLE [dbo].[OccurenceResultSet] (
    [IsPresent] bit  NOT NULL,
    [OccurrenceId] bigint  NOT NULL,
    [CandidateId] bigint  NOT NULL,
    [State] tinyint  NOT NULL
);
GO

-- Creating table 'AttachmentSet'
CREATE TABLE [dbo].[AttachmentSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [BinaryData] varbinary(max)  NOT NULL,
    [FileName] nvarchar(max)  NOT NULL,
    [ContentType] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [EntityBase_Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_GroupBase'
CREATE TABLE [dbo].[EntityBaseSet_GroupBase] (
    [GroupName] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_StudyGroup'
CREATE TABLE [dbo].[EntityBaseSet_StudyGroup] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_UserBase'
CREATE TABLE [dbo].[EntityBaseSet_UserBase] (
    [Login] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [FullName] nvarchar(max)  NOT NULL,
    [ShortName] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [RegisterDate] datetime  NOT NULL,
    [Gender] tinyint  NOT NULL,
    [Role] tinyint  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Coach'
CREATE TABLE [dbo].[EntityBaseSet_Coach] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Candidate'
CREATE TABLE [dbo].[EntityBaseSet_Candidate] (
    [Rank] tinyint  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_TaskBase'
CREATE TABLE [dbo].[EntityBaseSet_TaskBase] (
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [CreateDate] datetime  NOT NULL,
    [Id] bigint  NOT NULL,
    [Owner_Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Subject'
CREATE TABLE [dbo].[EntityBaseSet_Subject] (
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [CoachId] bigint  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Occurrence'
CREATE TABLE [dbo].[EntityBaseSet_Occurrence] (
    [From] datetime  NOT NULL,
    [To] datetime  NOT NULL,
    [Id] bigint  NOT NULL,
    [Schedule_SubjectId] bigint  NOT NULL,
    [Schedule_StudyGroupId] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_QuestionBase'
CREATE TABLE [dbo].[EntityBaseSet_QuestionBase] (
    [Text] nvarchar(max)  NOT NULL,
    [TimeOut] int  NOT NULL,
    [TestId] bigint  NOT NULL,
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_AnswerBase'
CREATE TABLE [dbo].[EntityBaseSet_AnswerBase] (
    [IsCorrect] bit  NOT NULL,
    [Text] nvarchar(max)  NOT NULL,
    [Chosen] bit  NOT NULL,
    [Id] bigint  NOT NULL,
    [QuestionBase_Id] bigint  NOT NULL,
    [ResultBase_Id] bigint  NULL
);
GO

-- Creating table 'EntityBaseSet_ResultBase'
CREATE TABLE [dbo].[EntityBaseSet_ResultBase] (
    [Status] tinyint  NOT NULL,
    [Id] bigint  NOT NULL,
    [Candidate_Id] bigint  NOT NULL,
    [TaskBase_Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_MarkBase'
CREATE TABLE [dbo].[EntityBaseSet_MarkBase] (
    [Value] float  NOT NULL,
    [Id] bigint  NOT NULL,
    [ResultBase_Id] bigint  NOT NULL,
    [OccurenceResult_OccurrenceId] bigint  NULL,
    [OccurenceResult_CandidateId] bigint  NULL
);
GO

-- Creating table 'EntityBaseSet_Test'
CREATE TABLE [dbo].[EntityBaseSet_Test] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Admin'
CREATE TABLE [dbo].[EntityBaseSet_Admin] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Coursework'
CREATE TABLE [dbo].[EntityBaseSet_Coursework] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Homework'
CREATE TABLE [dbo].[EntityBaseSet_Homework] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_SingleQuestion'
CREATE TABLE [dbo].[EntityBaseSet_SingleQuestion] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_SingleAnswer'
CREATE TABLE [dbo].[EntityBaseSet_SingleAnswer] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_TaskResult'
CREATE TABLE [dbo].[EntityBaseSet_TaskResult] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_TaskMark'
CREATE TABLE [dbo].[EntityBaseSet_TaskMark] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_FreeTextAnswer'
CREATE TABLE [dbo].[EntityBaseSet_FreeTextAnswer] (
    [Id] bigint  NOT NULL
);
GO

-- Creating table 'StudyGroupCouch'
CREATE TABLE [dbo].[StudyGroupCouch] (
    [StudyGroup_Id] bigint  NOT NULL,
    [Couch_Id] bigint  NOT NULL
);
GO

-- Creating table 'StudyGroupCandidate'
CREATE TABLE [dbo].[StudyGroupCandidate] (
    [StudyGroup_Id] bigint  NOT NULL,
    [Candidate_Id] bigint  NOT NULL
);
GO

-- Creating table 'CandidateTaskBase'
CREATE TABLE [dbo].[CandidateTaskBase] (
    [Candidate_Id] bigint  NOT NULL,
    [TaskBase_Id] bigint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'EntityBaseSet'
ALTER TABLE [dbo].[EntityBaseSet]
ADD CONSTRAINT [PK_EntityBaseSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [SubjectId], [StudyGroupId] in table 'ScheduleSet'
ALTER TABLE [dbo].[ScheduleSet]
ADD CONSTRAINT [PK_ScheduleSet]
    PRIMARY KEY CLUSTERED ([SubjectId], [StudyGroupId] ASC);
GO

-- Creating primary key on [OccurrenceId], [CandidateId] in table 'OccurenceResultSet'
ALTER TABLE [dbo].[OccurenceResultSet]
ADD CONSTRAINT [PK_OccurenceResultSet]
    PRIMARY KEY CLUSTERED ([OccurrenceId], [CandidateId] ASC);
GO

-- Creating primary key on [Id] in table 'AttachmentSet'
ALTER TABLE [dbo].[AttachmentSet]
ADD CONSTRAINT [PK_AttachmentSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_GroupBase'
ALTER TABLE [dbo].[EntityBaseSet_GroupBase]
ADD CONSTRAINT [PK_EntityBaseSet_GroupBase]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_StudyGroup'
ALTER TABLE [dbo].[EntityBaseSet_StudyGroup]
ADD CONSTRAINT [PK_EntityBaseSet_StudyGroup]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_UserBase'
ALTER TABLE [dbo].[EntityBaseSet_UserBase]
ADD CONSTRAINT [PK_EntityBaseSet_UserBase]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Coach'
ALTER TABLE [dbo].[EntityBaseSet_Coach]
ADD CONSTRAINT [PK_EntityBaseSet_Coach]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Candidate'
ALTER TABLE [dbo].[EntityBaseSet_Candidate]
ADD CONSTRAINT [PK_EntityBaseSet_Candidate]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_TaskBase'
ALTER TABLE [dbo].[EntityBaseSet_TaskBase]
ADD CONSTRAINT [PK_EntityBaseSet_TaskBase]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Subject'
ALTER TABLE [dbo].[EntityBaseSet_Subject]
ADD CONSTRAINT [PK_EntityBaseSet_Subject]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Occurrence'
ALTER TABLE [dbo].[EntityBaseSet_Occurrence]
ADD CONSTRAINT [PK_EntityBaseSet_Occurrence]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_QuestionBase'
ALTER TABLE [dbo].[EntityBaseSet_QuestionBase]
ADD CONSTRAINT [PK_EntityBaseSet_QuestionBase]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_AnswerBase'
ALTER TABLE [dbo].[EntityBaseSet_AnswerBase]
ADD CONSTRAINT [PK_EntityBaseSet_AnswerBase]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_ResultBase'
ALTER TABLE [dbo].[EntityBaseSet_ResultBase]
ADD CONSTRAINT [PK_EntityBaseSet_ResultBase]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_MarkBase'
ALTER TABLE [dbo].[EntityBaseSet_MarkBase]
ADD CONSTRAINT [PK_EntityBaseSet_MarkBase]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Test'
ALTER TABLE [dbo].[EntityBaseSet_Test]
ADD CONSTRAINT [PK_EntityBaseSet_Test]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Admin'
ALTER TABLE [dbo].[EntityBaseSet_Admin]
ADD CONSTRAINT [PK_EntityBaseSet_Admin]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Coursework'
ALTER TABLE [dbo].[EntityBaseSet_Coursework]
ADD CONSTRAINT [PK_EntityBaseSet_Coursework]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Homework'
ALTER TABLE [dbo].[EntityBaseSet_Homework]
ADD CONSTRAINT [PK_EntityBaseSet_Homework]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_SingleQuestion'
ALTER TABLE [dbo].[EntityBaseSet_SingleQuestion]
ADD CONSTRAINT [PK_EntityBaseSet_SingleQuestion]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_SingleAnswer'
ALTER TABLE [dbo].[EntityBaseSet_SingleAnswer]
ADD CONSTRAINT [PK_EntityBaseSet_SingleAnswer]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_TaskResult'
ALTER TABLE [dbo].[EntityBaseSet_TaskResult]
ADD CONSTRAINT [PK_EntityBaseSet_TaskResult]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_TaskMark'
ALTER TABLE [dbo].[EntityBaseSet_TaskMark]
ADD CONSTRAINT [PK_EntityBaseSet_TaskMark]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_FreeTextAnswer'
ALTER TABLE [dbo].[EntityBaseSet_FreeTextAnswer]
ADD CONSTRAINT [PK_EntityBaseSet_FreeTextAnswer]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [StudyGroup_Id], [Couch_Id] in table 'StudyGroupCouch'
ALTER TABLE [dbo].[StudyGroupCouch]
ADD CONSTRAINT [PK_StudyGroupCouch]
    PRIMARY KEY NONCLUSTERED ([StudyGroup_Id], [Couch_Id] ASC);
GO

-- Creating primary key on [StudyGroup_Id], [Candidate_Id] in table 'StudyGroupCandidate'
ALTER TABLE [dbo].[StudyGroupCandidate]
ADD CONSTRAINT [PK_StudyGroupCandidate]
    PRIMARY KEY NONCLUSTERED ([StudyGroup_Id], [Candidate_Id] ASC);
GO

-- Creating primary key on [Candidate_Id], [TaskBase_Id] in table 'CandidateTaskBase'
ALTER TABLE [dbo].[CandidateTaskBase]
ADD CONSTRAINT [PK_CandidateTaskBase]
    PRIMARY KEY NONCLUSTERED ([Candidate_Id], [TaskBase_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [StudyGroup_Id] in table 'StudyGroupCouch'
ALTER TABLE [dbo].[StudyGroupCouch]
ADD CONSTRAINT [FK_StudyGroupCouch_StudyGroup]
    FOREIGN KEY ([StudyGroup_Id])
    REFERENCES [dbo].[EntityBaseSet_StudyGroup]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Couch_Id] in table 'StudyGroupCouch'
ALTER TABLE [dbo].[StudyGroupCouch]
ADD CONSTRAINT [FK_StudyGroupCouch_Couch]
    FOREIGN KEY ([Couch_Id])
    REFERENCES [dbo].[EntityBaseSet_Coach]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StudyGroupCouch_Couch'
CREATE INDEX [IX_FK_StudyGroupCouch_Couch]
ON [dbo].[StudyGroupCouch]
    ([Couch_Id]);
GO

-- Creating foreign key on [StudyGroup_Id] in table 'StudyGroupCandidate'
ALTER TABLE [dbo].[StudyGroupCandidate]
ADD CONSTRAINT [FK_StudyGroupCandidate_StudyGroup]
    FOREIGN KEY ([StudyGroup_Id])
    REFERENCES [dbo].[EntityBaseSet_StudyGroup]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Candidate_Id] in table 'StudyGroupCandidate'
ALTER TABLE [dbo].[StudyGroupCandidate]
ADD CONSTRAINT [FK_StudyGroupCandidate_Candidate]
    FOREIGN KEY ([Candidate_Id])
    REFERENCES [dbo].[EntityBaseSet_Candidate]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StudyGroupCandidate_Candidate'
CREATE INDEX [IX_FK_StudyGroupCandidate_Candidate]
ON [dbo].[StudyGroupCandidate]
    ([Candidate_Id]);
GO

-- Creating foreign key on [Candidate_Id] in table 'CandidateTaskBase'
ALTER TABLE [dbo].[CandidateTaskBase]
ADD CONSTRAINT [FK_CandidateTaskBase_Candidate]
    FOREIGN KEY ([Candidate_Id])
    REFERENCES [dbo].[EntityBaseSet_Candidate]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [TaskBase_Id] in table 'CandidateTaskBase'
ALTER TABLE [dbo].[CandidateTaskBase]
ADD CONSTRAINT [FK_CandidateTaskBase_TaskBase]
    FOREIGN KEY ([TaskBase_Id])
    REFERENCES [dbo].[EntityBaseSet_TaskBase]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CandidateTaskBase_TaskBase'
CREATE INDEX [IX_FK_CandidateTaskBase_TaskBase]
ON [dbo].[CandidateTaskBase]
    ([TaskBase_Id]);
GO

-- Creating foreign key on [SubjectId] in table 'ScheduleSet'
ALTER TABLE [dbo].[ScheduleSet]
ADD CONSTRAINT [FK_SubjectSchedule]
    FOREIGN KEY ([SubjectId])
    REFERENCES [dbo].[EntityBaseSet_Subject]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [StudyGroupId] in table 'ScheduleSet'
ALTER TABLE [dbo].[ScheduleSet]
ADD CONSTRAINT [FK_StudyGroupSchedule]
    FOREIGN KEY ([StudyGroupId])
    REFERENCES [dbo].[EntityBaseSet_StudyGroup]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StudyGroupSchedule'
CREATE INDEX [IX_FK_StudyGroupSchedule]
ON [dbo].[ScheduleSet]
    ([StudyGroupId]);
GO

-- Creating foreign key on [Schedule_SubjectId], [Schedule_StudyGroupId] in table 'EntityBaseSet_Occurrence'
ALTER TABLE [dbo].[EntityBaseSet_Occurrence]
ADD CONSTRAINT [FK_ScheduleOccurrence]
    FOREIGN KEY ([Schedule_SubjectId], [Schedule_StudyGroupId])
    REFERENCES [dbo].[ScheduleSet]
        ([SubjectId], [StudyGroupId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ScheduleOccurrence'
CREATE INDEX [IX_FK_ScheduleOccurrence]
ON [dbo].[EntityBaseSet_Occurrence]
    ([Schedule_SubjectId], [Schedule_StudyGroupId]);
GO

-- Creating foreign key on [OccurrenceId] in table 'OccurenceResultSet'
ALTER TABLE [dbo].[OccurenceResultSet]
ADD CONSTRAINT [FK_OccurrenceOccurenceResult]
    FOREIGN KEY ([OccurrenceId])
    REFERENCES [dbo].[EntityBaseSet_Occurrence]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [CandidateId] in table 'OccurenceResultSet'
ALTER TABLE [dbo].[OccurenceResultSet]
ADD CONSTRAINT [FK_CandidateOccurenceResult]
    FOREIGN KEY ([CandidateId])
    REFERENCES [dbo].[EntityBaseSet_Candidate]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CandidateOccurenceResult'
CREATE INDEX [IX_FK_CandidateOccurenceResult]
ON [dbo].[OccurenceResultSet]
    ([CandidateId]);
GO

-- Creating foreign key on [QuestionBase_Id] in table 'EntityBaseSet_AnswerBase'
ALTER TABLE [dbo].[EntityBaseSet_AnswerBase]
ADD CONSTRAINT [FK_QuestionBaseAnswerBase]
    FOREIGN KEY ([QuestionBase_Id])
    REFERENCES [dbo].[EntityBaseSet_QuestionBase]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_QuestionBaseAnswerBase'
CREATE INDEX [IX_FK_QuestionBaseAnswerBase]
ON [dbo].[EntityBaseSet_AnswerBase]
    ([QuestionBase_Id]);
GO

-- Creating foreign key on [Candidate_Id] in table 'EntityBaseSet_ResultBase'
ALTER TABLE [dbo].[EntityBaseSet_ResultBase]
ADD CONSTRAINT [FK_ResultBaseCandidate]
    FOREIGN KEY ([Candidate_Id])
    REFERENCES [dbo].[EntityBaseSet_Candidate]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ResultBaseCandidate'
CREATE INDEX [IX_FK_ResultBaseCandidate]
ON [dbo].[EntityBaseSet_ResultBase]
    ([Candidate_Id]);
GO

-- Creating foreign key on [TaskBase_Id] in table 'EntityBaseSet_ResultBase'
ALTER TABLE [dbo].[EntityBaseSet_ResultBase]
ADD CONSTRAINT [FK_ResultBaseTaskBase]
    FOREIGN KEY ([TaskBase_Id])
    REFERENCES [dbo].[EntityBaseSet_TaskBase]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ResultBaseTaskBase'
CREATE INDEX [IX_FK_ResultBaseTaskBase]
ON [dbo].[EntityBaseSet_ResultBase]
    ([TaskBase_Id]);
GO

-- Creating foreign key on [ResultBase_Id] in table 'EntityBaseSet_MarkBase'
ALTER TABLE [dbo].[EntityBaseSet_MarkBase]
ADD CONSTRAINT [FK_MarkBaseResultBase]
    FOREIGN KEY ([ResultBase_Id])
    REFERENCES [dbo].[EntityBaseSet_ResultBase]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MarkBaseResultBase'
CREATE INDEX [IX_FK_MarkBaseResultBase]
ON [dbo].[EntityBaseSet_MarkBase]
    ([ResultBase_Id]);
GO

-- Creating foreign key on [OccurenceResult_OccurrenceId], [OccurenceResult_CandidateId] in table 'EntityBaseSet_MarkBase'
ALTER TABLE [dbo].[EntityBaseSet_MarkBase]
ADD CONSTRAINT [FK_MarkBaseOccurenceResult]
    FOREIGN KEY ([OccurenceResult_OccurrenceId], [OccurenceResult_CandidateId])
    REFERENCES [dbo].[OccurenceResultSet]
        ([OccurrenceId], [CandidateId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MarkBaseOccurenceResult'
CREATE INDEX [IX_FK_MarkBaseOccurenceResult]
ON [dbo].[EntityBaseSet_MarkBase]
    ([OccurenceResult_OccurrenceId], [OccurenceResult_CandidateId]);
GO

-- Creating foreign key on [Owner_Id] in table 'EntityBaseSet_TaskBase'
ALTER TABLE [dbo].[EntityBaseSet_TaskBase]
ADD CONSTRAINT [FK_TaskBaseUserBase]
    FOREIGN KEY ([Owner_Id])
    REFERENCES [dbo].[EntityBaseSet_UserBase]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TaskBaseUserBase'
CREATE INDEX [IX_FK_TaskBaseUserBase]
ON [dbo].[EntityBaseSet_TaskBase]
    ([Owner_Id]);
GO

-- Creating foreign key on [EntityBase_Id] in table 'AttachmentSet'
ALTER TABLE [dbo].[AttachmentSet]
ADD CONSTRAINT [FK_EntityBaseAttachment]
    FOREIGN KEY ([EntityBase_Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EntityBaseAttachment'
CREATE INDEX [IX_FK_EntityBaseAttachment]
ON [dbo].[AttachmentSet]
    ([EntityBase_Id]);
GO

-- Creating foreign key on [CoachId] in table 'EntityBaseSet_Subject'
ALTER TABLE [dbo].[EntityBaseSet_Subject]
ADD CONSTRAINT [FK_CoachSubject]
    FOREIGN KEY ([CoachId])
    REFERENCES [dbo].[EntityBaseSet_Coach]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CoachSubject'
CREATE INDEX [IX_FK_CoachSubject]
ON [dbo].[EntityBaseSet_Subject]
    ([CoachId]);
GO

-- Creating foreign key on [TestId] in table 'EntityBaseSet_QuestionBase'
ALTER TABLE [dbo].[EntityBaseSet_QuestionBase]
ADD CONSTRAINT [FK_TestQuestionBase]
    FOREIGN KEY ([TestId])
    REFERENCES [dbo].[EntityBaseSet_Test]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TestQuestionBase'
CREATE INDEX [IX_FK_TestQuestionBase]
ON [dbo].[EntityBaseSet_QuestionBase]
    ([TestId]);
GO

-- Creating foreign key on [ResultBase_Id] in table 'EntityBaseSet_AnswerBase'
ALTER TABLE [dbo].[EntityBaseSet_AnswerBase]
ADD CONSTRAINT [FK_AnswerBaseResultBase]
    FOREIGN KEY ([ResultBase_Id])
    REFERENCES [dbo].[EntityBaseSet_ResultBase]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnswerBaseResultBase'
CREATE INDEX [IX_FK_AnswerBaseResultBase]
ON [dbo].[EntityBaseSet_AnswerBase]
    ([ResultBase_Id]);
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_GroupBase'
ALTER TABLE [dbo].[EntityBaseSet_GroupBase]
ADD CONSTRAINT [FK_GroupBase_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_StudyGroup'
ALTER TABLE [dbo].[EntityBaseSet_StudyGroup]
ADD CONSTRAINT [FK_StudyGroup_inherits_GroupBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_GroupBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_UserBase'
ALTER TABLE [dbo].[EntityBaseSet_UserBase]
ADD CONSTRAINT [FK_UserBase_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Coach'
ALTER TABLE [dbo].[EntityBaseSet_Coach]
ADD CONSTRAINT [FK_Coach_inherits_UserBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_UserBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Candidate'
ALTER TABLE [dbo].[EntityBaseSet_Candidate]
ADD CONSTRAINT [FK_Candidate_inherits_UserBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_UserBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_TaskBase'
ALTER TABLE [dbo].[EntityBaseSet_TaskBase]
ADD CONSTRAINT [FK_TaskBase_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Subject'
ALTER TABLE [dbo].[EntityBaseSet_Subject]
ADD CONSTRAINT [FK_Subject_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Occurrence'
ALTER TABLE [dbo].[EntityBaseSet_Occurrence]
ADD CONSTRAINT [FK_Occurrence_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_QuestionBase'
ALTER TABLE [dbo].[EntityBaseSet_QuestionBase]
ADD CONSTRAINT [FK_QuestionBase_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_AnswerBase'
ALTER TABLE [dbo].[EntityBaseSet_AnswerBase]
ADD CONSTRAINT [FK_AnswerBase_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_ResultBase'
ALTER TABLE [dbo].[EntityBaseSet_ResultBase]
ADD CONSTRAINT [FK_ResultBase_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_MarkBase'
ALTER TABLE [dbo].[EntityBaseSet_MarkBase]
ADD CONSTRAINT [FK_MarkBase_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Test'
ALTER TABLE [dbo].[EntityBaseSet_Test]
ADD CONSTRAINT [FK_Test_inherits_TaskBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_TaskBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Admin'
ALTER TABLE [dbo].[EntityBaseSet_Admin]
ADD CONSTRAINT [FK_Admin_inherits_UserBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_UserBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Coursework'
ALTER TABLE [dbo].[EntityBaseSet_Coursework]
ADD CONSTRAINT [FK_Coursework_inherits_TaskBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_TaskBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Homework'
ALTER TABLE [dbo].[EntityBaseSet_Homework]
ADD CONSTRAINT [FK_Homework_inherits_TaskBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_TaskBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_SingleQuestion'
ALTER TABLE [dbo].[EntityBaseSet_SingleQuestion]
ADD CONSTRAINT [FK_SingleQuestion_inherits_QuestionBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_QuestionBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_SingleAnswer'
ALTER TABLE [dbo].[EntityBaseSet_SingleAnswer]
ADD CONSTRAINT [FK_SingleAnswer_inherits_AnswerBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_AnswerBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_TaskResult'
ALTER TABLE [dbo].[EntityBaseSet_TaskResult]
ADD CONSTRAINT [FK_TaskResult_inherits_ResultBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_ResultBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_TaskMark'
ALTER TABLE [dbo].[EntityBaseSet_TaskMark]
ADD CONSTRAINT [FK_TaskMark_inherits_MarkBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_MarkBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_FreeTextAnswer'
ALTER TABLE [dbo].[EntityBaseSet_FreeTextAnswer]
ADD CONSTRAINT [FK_FreeTextAnswer_inherits_AnswerBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet_AnswerBase]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------